package cn.fanxin.tools;

import java.util.HashMap;

/**
 * @Author: china-fanxin
 * @Website: https://fan-xin.cn
 * @Date: 2022/11/25 10:54
 * @Description: 生成基础指标计算汇总值的SQL部分
 */
public class CommonSumSql {

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成基础指标计算汇总值部分的SQL
     * @Date: 2022/11/25 0:31
     * @Param: [acctDate, kpiConfMap, etlConfMap]
     * @return: java.lang.String
     */
    public static String genBaseSumExecuteSql(String acctDate, HashMap<String,String> kpiConfMap){
        CommonPrint.printSumSqlStart();
        StringBuilder excuteSql = new StringBuilder();
        HashMap<String, HashMap<Integer, String>> etlConfMap = CommonCheck.etlConfMap;
        excuteSql.append(CommonSql.genDefineInsertSQL(acctDate,kpiConfMap,etlConfMap.get("dstColMap")))
                .append("\nSELECT * FROM (")
                .append(genBaseSumUnionAll(acctDate,kpiConfMap,etlConfMap).replaceAll("[\\n]","\n\t"))
                .append("\n);");
        return excuteSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成Mc基础指标计算汇总值部分的SQL
     * @Date: 2022/11/25 0:31
     * @Param: [acctDate, kpiConfMap, etlConfMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumExecuteSql(String acctDate, HashMap<String,String> kpiConfMap){
        CommonPrint.printSumSqlStart();
        StringBuilder excuteSql = new StringBuilder();
        HashMap<String, HashMap<Integer, String>> etlConfMap = CommonCheck.etlConfMap;
        excuteSql.append(CommonSql.genMcDefineInsertSQL(acctDate,kpiConfMap,etlConfMap.get("dstColMap")))
                .append(genMcBaseSumSelectSql(acctDate,etlConfMap.get("dstColMap")))
                .append(genMcBaseSumUnionAll(acctDate,kpiConfMap,etlConfMap).replaceAll("[\\n]","\n\t"))
                .append("\n);");
        return excuteSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 通过表结构生成插入语句。
     * @Date 2023/4/2 7:55
     * @Param: [acctDate, dstColMap]
     * @Return: java.lang.String
     */
    public static String genMcBaseSumSelectSql(String acctDate,HashMap<Integer, String> dstColMap) {
        String dateType = CommonFun.dateType(acctDate);
        StringBuilder res = new StringBuilder();
        res.append("SELECT \n\t");
        if (CommonCheck.isRelationMap){
            CommonCheck.dstColList.stream().forEach(dstCol->{
                if (!dateType.equals(dstCol)){
                    res.append(dstCol).append(",\n\t");
                }
            });
        }else{
            for (int i=0;i<dstColMap.size();i++){
                if (!dateType.equals(dstColMap.get(i))){
                    res.append(dstColMap.get(i)).append(",\n\t");
                }
            }
        }
        if (acctDate.length()==8){
            res.append("KPI_VALUE,\n\t")
                    .append("D_LD_VALUE,\n\t")
                    .append("M_TM_VALUE,\n\t")
                    .append("D_LM_VALUE,\n\t")
                    .append("M_LM_VALUE,\n\t")
                    .append("D_LY_VALUE,\n\t")
                    .append("M_LY_VALUE,\n\t")
                    .append("M_DA_VALUE,\n\t")
                    .append("M_LDA_VALUE \n");
        }else if (acctDate.length()==6){
            res.append("KPI_VALUE,\n\t")
                    .append("M_LM_VALUE,\n\t")
                    .append("Y_TY_VALUE,\n\t")
                    .append("M_LY_VALUE,\n\t")
                    .append("Y_LY_VALUE,\n\t")
                    .append("M_LY12_VALUE \n");
        }
        res.append("FROM (\n");
        return res.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成汇总值部分的union all语句
     * @Date: 2022/11/27 14:48
     * @Param: [acctDate, kpiConfMap, etlConfMap]
     * @return: java.lang.String
     */
    public static String genBaseSumUnionAll(String acctDate,HashMap<String,String> kpiConfMap, HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder unionAllSql = new StringBuilder();
        unionAllSql.append("\n\n/*省份汇总值*/\n")
                .append(genBaseSumProvSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumWhereSql(acctDate,kpiConfMap))
                .append(genSumProvGroupBySql(etlConfMap.get("dstColMap")))
                .append("\n\nUNION ALL\n\n/*全国汇总值*/\n")
                .append(genBaseSumAllSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumWhereSql(acctDate,kpiConfMap))
                .append(genSumAllGroupBySql(etlConfMap.get("dstColMap")))
                .append("\n\nUNION ALL\n\n/*北10汇总值*/\n")
                .append(genBaseSumNorthSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumNorthWhereSql(acctDate,kpiConfMap))
                .append(genSumNorthGroupBySql(etlConfMap.get("dstColMap")))
                .append("\n\nUNION ALL\n\n/*南21汇总值*/\n")
                .append(genBaseSumSouthSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumSouthWhereSql(acctDate,kpiConfMap))
                .append(genSumSouthGroupBySql(etlConfMap.get("dstColMap")));
        return  unionAllSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成汇总值部分的union all语句
     * @Date: 2022/11/27 14:48
     * @Param: [acctDate, kpiConfMap, etlConfMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumUnionAll(String acctDate,HashMap<String,String> kpiConfMap, HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder unionAllSql = new StringBuilder();
        unionAllSql
                .append(genMcBaseSumProvSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumWhereSql(acctDate,kpiConfMap))
                .append(genSumProvGroupBySql(etlConfMap.get("dstColMap")))
                .append("\nUNION ALL\n")
                .append(genMcBaseSumAllSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumWhereSql(acctDate,kpiConfMap))
                .append(genSumAllGroupBySql(etlConfMap.get("dstColMap")))
                .append("\nUNION ALL\n")
                .append(genMcBaseSumNorthSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumNorthWhereSql(acctDate,kpiConfMap))
                .append(genSumNorthGroupBySql(etlConfMap.get("dstColMap")))
                .append("\nUNION ALL\n")
                .append(genMcBaseSumSouthSelectSQL(acctDate,kpiConfMap,etlConfMap))
                .append(genBaseSumSouthWhereSql(acctDate,kpiConfMap))
                .append(genSumSouthGroupBySql(etlConfMap.get("dstColMap")));
        return  unionAllSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成所有汇总值公共部分的固定查询语句
     * @Date: 2022/11/26 20:49
     * @Param: [acctDate, kpiConfMap]
     * @return: java.lang.String
     */
    public static String genPubSelectSql(String acctDate,HashMap<String,String> kpiConfMap){
        StringBuilder selectSql = new StringBuilder();
        if (acctDate.length()==8){
            selectSql.append("'"+kpiConfMap.get("KPI_CODE")+"' AS KPI_CODE,")
                    .append("\n\tCAST(SUM(KPI_VALUE) AS DECIMAL(54,18)) AS KPI_VALUE,")
                    .append("\n\tCAST(SUM(D_LD_VALUE) AS DECIMAL(54,18)) AS D_LD_VALUE,")
                    .append("\n\tCAST(SUM(M_TM_VALUE) AS DECIMAL(54,18)) AS M_TM_VALUE,")
                    .append("\n\tCAST(SUM(D_LM_VALUE) AS DECIMAL(54,18)) AS D_LM_VALUE,")
                    .append("\n\tCAST(SUM(M_LM_VALUE) AS DECIMAL(54,18)) AS M_LM_VALUE,")
                    .append("\n\tCAST(SUM(D_LY_VALUE) AS DECIMAL(54,18)) AS D_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY_VALUE) AS DECIMAL(54,18)) AS M_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_DA_VALUE) AS DECIMAL(54,18)) AS M_DA_VALUE,")
                    .append("\n\tCAST(SUM(M_LDA_VALUE) AS DECIMAL(54,18)) AS M_LDA_VALUE")
                    .append("\nFROM ").append(kpiConfMap.get("DST_ENTITY_OWNER")).append(".").append(kpiConfMap.get("DST_ENTITY_NAME"));
        }else if (acctDate.length()==6){
            selectSql.append("'"+kpiConfMap.get("KPI_CODE")+"' AS KPI_CODE,")
                    .append("\n\tCAST(SUM(KPI_VALUE) AS DECIMAL(54,18)) AS KPI_VALUE,")
                    .append("\n\tCAST(SUM(M_LM_VALUE) AS DECIMAL(54,18)) AS M_LM_VALUE,")
                    .append("\n\tCAST(SUM(Y_TY_VALUE) AS DECIMAL(54,18)) AS Y_TY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY_VALUE) AS DECIMAL(54,18)) AS M_LY_VALUE,")
                    .append("\n\tCAST(SUM(Y_LY_VALUE) AS DECIMAL(54,18)) AS Y_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY12_VALUE) AS DECIMAL(54,18)) AS M_LY12_VALUE")
                    .append("\nFROM ").append(kpiConfMap.get("DST_ENTITY_OWNER")).append(".").append(kpiConfMap.get("DST_ENTITY_NAME"));
        }
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成MC环境下所有汇总值公共部分的固定查询语句
     * @Date 2023/4/2 9:21
     * @Param: [acctDate, kpiConfMap]
     * @Return: java.lang.String
     */
    public static String genMcPubSelectSql(String acctDate,HashMap<String,String> kpiConfMap){
        StringBuilder selectSql = new StringBuilder();
        if (acctDate.length()==8){
            selectSql.append("'"+kpiConfMap.get("KPI_CODE")+"' AS KPI_CODE,")
                    .append("\n\tCAST(SUM(KPI_VALUE) AS DECIMAL(38,18)) AS KPI_VALUE,")
                    .append("\n\tCAST(SUM(D_LD_VALUE) AS DECIMAL(38,18)) AS D_LD_VALUE,")
                    .append("\n\tCAST(SUM(M_TM_VALUE) AS DECIMAL(38,18)) AS M_TM_VALUE,")
                    .append("\n\tCAST(SUM(D_LM_VALUE) AS DECIMAL(38,18)) AS D_LM_VALUE,")
                    .append("\n\tCAST(SUM(M_LM_VALUE) AS DECIMAL(38,18)) AS M_LM_VALUE,")
                    .append("\n\tCAST(SUM(D_LY_VALUE) AS DECIMAL(38,18)) AS D_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY_VALUE) AS DECIMAL(38,18)) AS M_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_DA_VALUE) AS DECIMAL(38,18)) AS M_DA_VALUE,")
                    .append("\n\tCAST(SUM(M_LDA_VALUE) AS DECIMAL(38,18)) AS M_LDA_VALUE")
                    .append("\nFROM ");
        }else if (acctDate.length()==6){
            selectSql.append("'"+kpiConfMap.get("KPI_CODE")+"' AS KPI_CODE,")
                    .append("\n\tCAST(SUM(KPI_VALUE) AS DECIMAL(38,18)) AS KPI_VALUE,")
                    .append("\n\tCAST(SUM(M_LM_VALUE) AS DECIMAL(38,18)) AS M_LM_VALUE,")
                    .append("\n\tCAST(SUM(Y_TY_VALUE) AS DECIMAL(38,18)) AS Y_TY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY_VALUE) AS DECIMAL(38,18)) AS M_LY_VALUE,")
                    .append("\n\tCAST(SUM(Y_LY_VALUE) AS DECIMAL(38,18)) AS Y_LY_VALUE,")
                    .append("\n\tCAST(SUM(M_LY12_VALUE) AS DECIMAL(38,18)) AS M_LY12_VALUE")
                    .append("\nFROM ");
        }
        selectSql.append(CommonSql.genMcTransferTableSql(kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（省份汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genBaseSumProvSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（省份汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumProvSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genMcPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（全国汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genBaseSumAllSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        //进行汇总计算时，select的来源表是基础指标配置表中的目标表
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'111' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（全国汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumAllSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        //进行汇总计算时，select的来源表是基础指标配置表中的目标表
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'111' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genMcPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（北10汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genBaseSumNorthSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'112' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（北10汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumNorthSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'112' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genMcPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（南21汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genBaseSumSouthSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'113' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据配置表生成基础指标 select 语句部分（南21汇总值部分）
     * @Date: 2022/11/22 19:46
     * @Param: [kpiConfMap, srcColMap]
     * @return: java.lang.String
     */
    public static String genMcBaseSumSouthSelectSQL(String acctDate,HashMap<String,String> kpiConfMap,HashMap<String,HashMap<Integer,String>> etlConfMap){
        StringBuilder selectSql = new StringBuilder();
        selectSql.append("\nSELECT\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                selectSql.append("'-1' AS AREA_ID,\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                selectSql.append("'113' AS PROV_ID,\n\t");
            }else {
                selectSql.append(dstCol).append(",\n\t");
            }
        });
        selectSql.append(genMcPubSelectSql(acctDate,kpiConfMap));
        return selectSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成基础指标 限定条件部分 （汇总值）
     * @Date: 2022/11/20 21:05
     * @Param: [acctDate, kpiConfMap]
     * @return: java.lang.String
     */
    public static String genBaseSumWhereSql(String acctDate,HashMap<String,String> kpiConfMap){
        String dateType = CommonFun.dateType(acctDate);
        StringBuilder whereConditionSql = new StringBuilder();
        whereConditionSql.append("\nWHERE ").append(dateType).append(" = '").append(acctDate).append("'")
                .append("\n\tAND KPI_CODE = '").append(kpiConfMap.get("KPI_CODE")).append("'")
                .append("\n\tAND AREA_ID != '-1'");
        return whereConditionSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成基础指标 限定条件部分 （汇总值部分） 北10省
     * @Date: 2022/11/20 21:05
     * @Param: [acctDate, kpiConfMap]
     * @return: java.lang.String
     */
    public static String genBaseSumNorthWhereSql(String acctDate,HashMap<String,String> kpiConfMap){
        String dateType = CommonFun.dateType(acctDate);
        StringBuilder whereConditionSql = new StringBuilder();
        whereConditionSql.append("\nWHERE ").append(dateType).append(" = '").append(acctDate).append("'")
                .append("\n\tAND KPI_CODE = '").append(kpiConfMap.get("KPI_CODE")).append("'")
                .append("\n\tAND AREA_ID != '-1'")
                .append("\n\tAND PROV_ID IN ('010','011','013','017','018','019','076','090','091','097')");
        return whereConditionSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 生成基础指标 限定条件部分 （汇总值部分） 南21省
     * @Date: 2022/11/20 21:05
     * @Param: [acctDate, kpiConfMap]
     * @return: java.lang.String
     */
    public static String genBaseSumSouthWhereSql(String acctDate,HashMap<String,String> kpiConfMap){
        String dateType = CommonFun.dateType(acctDate);
        StringBuilder whereConditionSql = new StringBuilder();
        whereConditionSql.append("\nWHERE ").append(dateType).append(" = '").append(acctDate).append("'")
                .append("\n\tAND KPI_CODE = '").append(kpiConfMap.get("KPI_CODE")).append("'")
                .append("\n\tAND AREA_ID != '-1'")
                .append("\n\tAND PROV_ID IN ('030', '031', '034', '036', '038', '050', '051', '059', '070', '071', '074', '075', '079', '081', '083', '084', '085', '086', '087', '088', '089')");;
        return whereConditionSql.toString();
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据ETL配置，生成汇总值部分的GROUP BY语句(省份汇总）
     * @Date: 2022/11/25 10:03
     * @Param: [srcColMap]
     * @return: java.lang.String
     */
    public static String genSumProvGroupBySql(HashMap<Integer,String> srcColMap){
        //定义需要group by汇总的字段列表
        StringBuilder groupBySql = new StringBuilder();
        groupBySql.append("\nGROUP BY\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                groupBySql.append("'-1',\n\t");
            }else {
                groupBySql.append(dstCol).append(",\n\t");
            }
        });
        String res = groupBySql.toString();
        res = res.substring(0,res.length()-3);
        return res;
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据ETL配置，生成汇总值部分的GROUP BY语句(全国汇总）
     * @Date: 2022/11/25 10:03
     * @Param: [srcColMap]
     * @return: java.lang.String
     */
    public static String genSumAllGroupBySql(HashMap<Integer,String> srcColMap){
        //定义需要group by汇总的字段列表
        StringBuilder groupBySql = new StringBuilder();
        groupBySql.append("\nGROUP BY\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                groupBySql.append("'-1',\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                groupBySql.append("'111',\n\t");
            }else {
                groupBySql.append(dstCol).append(",\n\t");
            }
        });
        String res = groupBySql.toString();
        res = res.substring(0,res.length()-3);
        return res;
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据ETL配置，生成汇总值部分的GROUP BY语句(北10汇总）
     * @Date: 2022/11/25 10:03
     * @Param: [srcColMap]
     * @return: java.lang.String
     */
    public static String genSumNorthGroupBySql(HashMap<Integer,String> srcColMap){
        //定义需要group by汇总的字段列表
        StringBuilder groupBySql = new StringBuilder();
        groupBySql.append("\nGROUP BY\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                groupBySql.append("'-1',\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                groupBySql.append("'112',\n\t");
            }else {
                groupBySql.append(dstCol).append(",\n\t");
            }
        });
        String res = groupBySql.toString();
        res = res.substring(0,res.length()-3);
        return res;
    }

    /**
     * @Author: china-fanxin
     * @Website: https://fan-xin.cn
     * @Description: 根据ETL配置，生成汇总值部分的GROUP BY语句(南21汇总）
     * @Date: 2022/11/25 10:03
     * @Param: [srcColMap]
     * @return: java.lang.String
     */
    public static String genSumSouthGroupBySql(HashMap<Integer,String> srcColMap){
        //定义需要group by汇总的字段列表
        StringBuilder groupBySql = new StringBuilder();
        groupBySql.append("\nGROUP BY\n\t");
        CommonCheck.dstColList.stream().forEach(dstCol->{
            if("AREA_ID".equals(dstCol)){
                groupBySql.append("'-1',\n\t");
            }else if ("PROV_ID".equals(dstCol)){
                groupBySql.append("'113',\n\t");
            }else {
                groupBySql.append(dstCol).append(",\n\t");
            }
        });
        String res = groupBySql.toString();
        res = res.substring(0,res.length()-3);
        return res;
    }

}